package main

import (
	capi "dfs/server/master/api/client"
	wapi "dfs/server/master/api/worker"
	"dfs/server/master/config"
	cservice "dfs/server/master/service/client"
	wservice "dfs/server/master/service/worker"
	"fmt"
	"net"

	"google.golang.org/grpc"
)

func main() {
	stop := make(chan struct{})
	defer close(stop)

	// start ResourceManager
	wservice.Init()
	go wservice.Scan(3, stop)

	// start RPC-Server
	conn, err := net.Listen("tcp", fmt.Sprintf(":%d", config.Port))
	if err != nil {
		fmt.Printf("监听端口%d失败\n", config.Port)
		return
	}
	server := grpc.NewServer()
	wapi.RegisterWorkerServiceServer(server, &wservice.WorkerService{})
	capi.RegisterClientServiceServer(server, &cservice.ClientService{})
	server.Serve(conn)
}
